package com.yhy.common.feign.interceptor;

import com.yhy.common.core.constant.SecurityConstants;
import com.yhy.common.core.utils.WebUtils;
import feign.Feign;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@ConditionalOnClass(Feign.class)
public class FeignRequestInterceptor implements RequestInterceptor {

    @Override
    @SuppressWarnings({"all"})
    public void apply(RequestTemplate requestTemplate) {
        HttpServletRequest request = WebUtils.getRequest();
        requestTemplate.header(SecurityConstants.DETAILS_USER, request.getHeader(SecurityConstants.DETAILS_USER));
        requestTemplate.header(SecurityConstants.JWT_PAYLOAD_KEY, request.getHeader(SecurityConstants.JWT_PAYLOAD_KEY));
        requestTemplate.header(SecurityConstants.JWT_JTI, request.getHeader(SecurityConstants.JWT_JTI));
        requestTemplate.header(SecurityConstants.JWT_EXP, request.getHeader(SecurityConstants.JWT_EXP));
    }
}
